import 'package:im_base/im_base.dart';
import 'package:im_base/public/ext/im_base_controller.dart';
import 'package:im_base/public/service/tim_service.dart';
import 'package:tencent_im_sdk_plugin/models/v2_tim_friend_info.dart';

class BlackListLogic extends IMBaseController {
  bool hasMore = false;
  var blackList = List<V2TimFriendInfo>.empty(growable: true);

  @override
  void onInit() {
    loading();
    super.onInit();
  }

  @override
  void onReady() {
    loadData();
    super.onReady();
  }

  void loadMore() {}

  Future loadData() async {
    blackList = await TimService.instance.getBlackList();
    if (blackList.isEmpty) {
      status = LoadStatus.EMPTY;
    } else {
      status = LoadStatus.FINISHED;
    }
    update();
  }

  ///将用户移出黑名单,同时修改用户资料作为标识
  void removeBlack(V2TimFriendInfo info) async {
   var result= await TimService.instance.deleteFromBlackList(info.userID);
   if(result!=null){
     blackList.removeWhere((element) => element.userID==result.userID);
     update(['list']);
   }
  }
}
